package com.alex.insistence.web.wechat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

//import me.chanjar.weixin.common.api.WxConsts;
//import me.chanjar.weixin.common.bean.WxJsapiSignature;
//import me.chanjar.weixin.common.exception.WxErrorException;
//import me.chanjar.weixin.mp.api.WxMpService;

@Controller
@RequestMapping(value = "carwxRedirectController")
public class CarwxRedirectController {
  private static final Logger logger = LoggerFactory.getLogger(CarwxRedirectController.class);

  // @Autowired
  // private SystemService systemService;
  // @Autowired
  // private StationServiceI stationService;
  // @Autowired
  // private OrderServiceI orderService;
  // @Autowired
  // private WxMpService wxMpService;
  // @Autowired
  // private AlipayGzuserinfoDao alipayGzuserinfoDao;
  // @Autowired
  // private MemberServiceI mbrService;
  // @Autowired
  // private AlipayGzuserinfoDao userDao;
  // @Autowired
  // private InvoiceServiceI invoiceServiceI;
  // @Autowired
  // private StationUserServiceI stationUserService;
  // @Autowired
  // private WxFansServiceI wxFansService;
  // @Autowired
  // private CouponStockServiceI couponStockService;
  //
  // @RequestMapping(params = "order")
  // public String order(HttpServletRequest request, HttpServletResponse
  // response) {
  // String public_id =
  // request.getParameter(InitWapContextFilter.PARAM_PUBLIC_ID);
  // String stationCode =
  // request.getParameter(InitWapContextFilter.PARAM_SATION_CODE);
  // String stationUserLogin =
  // request.getParameter(InitWapContextFilter.PARAM_SATION_USER_LOGIN);
  // String appid = request.getParameter(InitWapContextFilter.PARAM_APP_ID);
  // request.setAttribute("stationCode", stationCode);
  // request.setAttribute("stationUserLogin", stationUserLogin);
  // request.setAttribute("public_id", public_id);
  // request.setAttribute("appid", appid);
  // return "carwx/order";
  // }
  //
  // @RequestMapping(params = "storeInMap")
  // public String storeInMap(HttpServletRequest request, HttpServletResponse
  // response) {
  // List<StationEntity> list = systemService.getList(StationEntity.class);
  // JSONArray jsarray = new JSONArray();
  // for (StationEntity station : list) {
  // JSONObject js = new JSONObject();
  // js.put("longitude", station.getLongitude());
  // js.put("latitude", station.getLatitude());
  // js.put("departname", station.getDepartname());
  // js.put("address", station.getAddress());
  // js.put("id", station.getId());
  // jsarray.add(js);
  // }
  //
  // request.setAttribute("stationList", jsarray.toJSONString());
  // return "carwx/storeInMap";
  // }
  //
  // @RequestMapping(params = "storeList")
  // public String storeList(HttpServletRequest request, HttpServletResponse
  // response) {
  // List<StationEntity> list = systemService.getList(StationEntity.class);
  // request.setAttribute("stationList", list);
  // return "carwx/storeList";
  // }
  //
  // @RequestMapping(params = "storeDetail")
  // public String storeDetail(HttpServletRequest request, HttpServletResponse
  // response) {
  // String id = request.getParameter("id");
  // StationEntity station = systemService.getEntity(StationEntity.class, id);
  // List<StationGasItemEntity> gasItemList = systemService
  // .findByProperty(StationGasItemEntity.class, "stationId", id);
  // request.setAttribute("station", station);
  // request.setAttribute("gasItemList", gasItemList);
  // return "carwx/storeDetail";
  // }
  //
  // @RequestMapping(params = "refuelingSheet")
  // public String refuelingSheet(HttpServletRequest request,
  // HttpServletResponse response)
  // throws IOException, WxErrorException, AlipayApiException {
  // String openid = request.getParameter("openid");
  // String alipayUserId = request.getParameter("alipayUserId");
  // String public_id =
  // request.getParameter(InitWapContextFilter.PARAM_PUBLIC_ID);
  // String users = "";
  // String stationCode =
  // request.getParameter(InitWapContextFilter.PARAM_SATION_CODE);
  // String stationUserLogin =
  // request.getParameter(InitWapContextFilter.PARAM_SATION_USER_LOGIN);
  //
  // StationEntity station = null;
  // if (StringUtils.isNotBlank(stationCode)) {
  // station = systemService.findUniqueByProperty(StationEntity.class,
  // "orgCode", stationCode);
  // }
  // if (station == null) {
  // request.setAttribute("msg", "没有指定油站！");
  // return "carwx/error";
  // }
  //
  // StationUserEntity stationUser = null;
  // if (StringUtils.isNotBlank(stationUserLogin)) {
  // stationUser = systemService.findUniqueByProperty(StationUserEntity.class,
  // "userName",
  // stationUserLogin);
  // }
  // if (stationUser == null) {
  // request.setAttribute("msg", "没有指定油站人员！");
  // return "carwx/error";
  // }
  //
  // // if (stationCode != null && !"".equals(stationCode)) {
  // // station = systemService.findUniqueByProperty(StationEntity.class,
  // // "orgCode", stationCode);
  // // if (stationUserLogin != null && !"".equals(stationUserLogin)) {
  // // stationUser =
  // // systemService.findUniqueByProperty(StationUserEntity.class,
  // // "userName",
  // // stationUserLogin);
  // // }
  // //
  // // if (station != null) {
  // // // TODO 这里的油站人员必须不能为空，目前应该不再支持微信上选油站人员加油了。
  // // List<StationUserEntity> stationUsers =
  // // systemService.findByProperty(StationUserEntity.class,
  // // "departid", station.getId());
  // // if (stationUsers.size() > 0 && stationUser == null) {
  // // stationUser = stationUsers.get(0);
  // // }
  // // for (StationUserEntity stationUserEntity : stationUsers) {
  // // users = users + "," + "'" + stationUserEntity.getRealName() + "["
  // // + stationUserEntity.getWorknum() + "]" + "'";
  // // }
  // // } else {
  // // request.setAttribute("msg", "没找到油站！");
  // // return "carwx/error";
  // // }
  // // CriteriaQuery cq = new CriteriaQuery(OilGunEntity.class);
  // // cq.eq("stationId", station.getId());
  // // cq.addOrder("code", SortDirection.asc);
  // // cq.add();
  // // oilGunsList = systemService.getListByCriteriaQuery(cq, false);
  // // } else {
  // // request.setAttribute("msg", "没找到油站！");
  // // return "carwx/error";
  // // }
  //
  // List<OilGunEntity> oilGunsList = getStationOilGuns(station.getId());
  // String oilGuns = "";
  // for (OilGunEntity oilGunEntity : oilGunsList) {
  // oilGuns = oilGuns + "," + "'" + oilGunEntity.getName() + "'";
  // }
  // request.setAttribute("oilGuns", oilGuns.replaceFirst(",", ""));
  // request.setAttribute("oilGunsList", oilGunsList);
  //
  // // TODO 这里为什么要查询全部油站人员???
  // /*
  // * List<StationUserEntity> userList =
  // * systemService.getList(StationUserEntity.class);
  // * request.setAttribute("userList", userList);
  // *
  // * List<StationEntity> stationList =
  // * systemService.getList(StationEntity.class);
  // * request.setAttribute("stationList", stationList);
  // *
  // * String stations = ""; for (StationEntity stationEntity : stationList) {
  // * stations = stations + "," + "'" + stationEntity.getDepartname() + "'"; }
  // */
  //
  // List<StationGasItemEntity> gasItemList = systemService
  // .findByProperty(StationGasItemEntity.class, "stationId", station.getId());
  // MemberEntity member =
  // systemService.findUniqueByProperty(MemberEntity.class, "wxid", openid);
  // if (member != null) {
  // List<MemberVehicleEntity> mvh =
  // systemService.findByProperty(MemberVehicleEntity.class,
  // "memberId", member.getId());
  // if (mvh.size() > 0) {
  // request.setAttribute("vehicleNo", mvh.get(0).getVehicleNo());
  // }
  // }
  //
  // request.setAttribute("users", users.replaceFirst(",", ""));
  // // request.setAttribute("stations", stations.replaceFirst(",", ""));
  // request.setAttribute("stationUser", stationUser);
  // request.setAttribute("station", station);
  // request.setAttribute("gasItemList", gasItemList);
  // request.setAttribute("public_id", public_id);
  // request.setAttribute("openid", openid);
  // request.setAttribute("alipayUserId", alipayUserId);
  // return "carwx/refuelingSheet";
  // }
  //
  // private List<OilGunEntity> getStationOilGuns(String stationId) {
  // CriteriaQuery cq = new CriteriaQuery(OilGunEntity.class);
  // cq.eq("stationId", stationId);
  // cq.addOrder("code", SortDirection.asc);
  // cq.add();
  // List<OilGunEntity> oilGunsList = systemService.getListByCriteriaQuery(cq,
  // false);
  // return oilGunsList;
  // }
  //
  // @RequestMapping(params = "mycar")
  // public String mycar(HttpServletRequest request, HttpServletResponse
  // response) {
  // return "carwx/mycar";
  // }
  //
  // @RequestMapping(params = "fueRecord")
  // public String fueRecord(HttpServletRequest request, HttpServletResponse
  // response) {
  // String memberId = request.getParameter("memberId");
  // if (StringUtils.isBlank(memberId)) {
  // request.setAttribute("msg", "没找到当前会员！");
  // return "carwx/error";
  // }
  // CriteriaQuery cq = new CriteriaQuery(OrderEntity.class);
  // cq.eq("memberId", memberId);
  // cq.eq("state", OrderStates.PAID);
  // cq.addOrder("createDate", SortDirection.desc);
  // cq.add();
  // List<OrderEntity> list = systemService.getListByCriteriaQuery(cq, false);
  // request.setAttribute("orderList", list);
  // return "carwx/fueRecord";
  // }
  //
  // @RequestMapping(params = "coupon")
  // public String coupon(HttpServletRequest request, HttpServletResponse
  // response)
  // throws WxErrorException, IOException {
  // String memberId = request.getParameter("memberId");
  // if (!StringUtils.isEmpty(memberId)) {
  // setCouponStock(memberId, request);
  // request.setAttribute("memberId", memberId);
  // return "carwx/coupon";
  // }
  // String openid = request.getParameter("openid");
  // String alipayUserId = request.getParameter("alipayUserId");
  // MemberEntity member = new MemberEntity();
  // if (StringUtils.isNotBlank(openid)) {
  // member = systemService.findUniqueByProperty(MemberEntity.class, "wxid",
  // openid);
  // } else if (StringUtils.isNotBlank(alipayUserId)) {
  // member = systemService.findUniqueByProperty(MemberEntity.class, "alipayid",
  // alipayUserId);
  // } else {
  // member = systemService.getEntity(MemberEntity.class, memberId);
  // }
  // if (member != null) {
  // setCouponStock(member.getId(), request);
  // memberId = member.getId();
  // } else {
  // request.setAttribute("msg", "没找到当前会员！");
  // return "carwx/error";
  // }
  // request.setAttribute("memberId", memberId);
  // setCouponStock(memberId, request);
  // return "carwx/coupon";
  // }
  //
  // @RequestMapping(params = "gasCoupon")
  // public String gasCoupon(HttpServletRequest request, HttpServletResponse
  // response) {
  // return "carwx/gasCoupon";
  // }
  //
  // @RequestMapping(params = "memCenter")
  // public String memCenter(HttpServletRequest request, HttpServletResponse
  // response)
  // throws WxErrorException, IOException, AlipayApiException {
  // String memberId = request.getParameter("memberId");
  // String openid = request.getParameter("openid");
  // String alipayUserId = request.getParameter("alipayUserId");
  // MemberEntity member = null;
  // if (StringUtils.isNotBlank(openid)) {
  // member = systemService.findUniqueByProperty(MemberEntity.class, "wxid",
  // openid);
  // } else if (StringUtils.isNotBlank(alipayUserId)) {
  // member = systemService.findUniqueByProperty(MemberEntity.class, "alipayid",
  // alipayUserId);
  // } else {
  // member = systemService.getEntity(MemberEntity.class, memberId);
  // }
  // if (member == null) {
  // request.setAttribute("msg", "没找到当前会员！");
  // return "carwx/error";
  // }
  // request.setAttribute("member", member);
  // return "carwx/memCenter";
  // }
  //
  // @RequestMapping(params = "paySuccess")
  // public String paySuccess(HttpServletRequest request, HttpServletResponse
  // response) {
  // String openid = request.getParameter("openid");
  // String billNumber = request.getParameter("billNumber");
  // OrderEntity order = systemService.findUniqueByProperty(OrderEntity.class,
  // "billNumber",
  // billNumber);
  // CommentEntity comment =
  // systemService.findUniqueByProperty(CommentEntity.class, "orderNumber",
  // billNumber);
  // if (comment != null) {
  // List<CommentDetailEntity> comdetailList = systemService
  // .findByProperty(CommentDetailEntity.class, "commentId", comment.getId());
  // request.setAttribute("comdetailList",
  // JSONArray.toJSONString(comdetailList));
  // }
  // request.setAttribute("order", order);
  // WxFansEntity fans = WxContext.getWxUser();
  // if (fans == null) {
  // fans = systemService.findUniqueByProperty(WxFansEntity.class, "openid",
  // openid);
  // }
  // request.setAttribute("wxfans", fans);
  // return "carwx/paySuccess";
  // }
  //
  // @RequestMapping(params = "confirm")
  // public String confirm(HttpServletRequest request, HttpServletResponse
  // response) {
  // String public_id = request.getParameter("public_id");
  // String openid = request.getParameter("openid");
  // String id = request.getParameter("orderId");
  // logger.info("order info==========" + id);
  // OrderEntity order = orderService.getEntity(OrderEntity.class, id);
  // logger.info("order info==========" + order.toString());
  // logger.info("order info==========ordreTotal:" + order.getTotal() +
  // "orderRealPay:"
  // + order.getRealPayTotal());
  // request.setAttribute("order", order);
  // request.setAttribute("cast",
  // order.getTotal().subtract(order.getRealPayTotal()));
  // request.setAttribute("public_id", public_id);
  // request.setAttribute("openid", openid);
  // request.setAttribute("stationUserId",
  // request.getParameter("stationUserId"));
  // request.setAttribute("stationId", request.getParameter("stationId"));
  // return "carwx/confirm";
  // }
  //
  // @RequestMapping(params = "openewm")
  // public String openewm(HttpServletRequest request, HttpServletResponse
  // response)
  // throws WxErrorException {
  // WxJsapiSignature wxJsapiSignature = this.wxMpService
  // .createJsapiSignature(request.getRequestURL().toString() + "?" +
  // request.getQueryString());
  // request.setAttribute("appId",
  // this.wxMpService.getWxMpConfigStorage().getAppId());
  // request.setAttribute("timestamp", wxJsapiSignature.getTimestamp());
  // request.setAttribute("nonceStr", wxJsapiSignature.getNoncestr());
  // // payInfo.put("appId",
  // // this.wxMpService.getWxMpConfigStorage().getAppId());
  // request.setAttribute("signature", wxJsapiSignature.getSignature());
  // return "carwx/openewm";
  // }
  //
  // @RequestMapping(params = "tostation")
  // public String tostation(HttpServletRequest request, HttpServletResponse
  // response)
  // throws WxErrorException {
  // String longitude = request.getParameter("longitude");
  // String latitude = request.getParameter("latitude");
  // request.setAttribute("longitude", longitude);
  // request.setAttribute("latitude", latitude);
  // return "carwx/tostation";
  // }
  //
  // @RequestMapping(params = "bill")
  // public String bill(HttpServletRequest request, HttpServletResponse
  // response) throws Exception {
  // String memberId = request.getParameter("memberId");
  // if (StringUtils.isBlank(memberId)) {
  // request.setAttribute("msg", "没找到当前会员！");
  // return "carwx/error";
  // }
  // CriteriaQuery cq = new CriteriaQuery(OrderEntity.class);
  // cq.eq("memberId", memberId);
  // cq.eq("state", OrderStates.PAID);
  // cq.eq("invoice", "N");
  // cq.add();
  // List<OrderEntity> list = systemService.getListByCriteriaQuery(cq, false);
  // request.setAttribute("orderList", list);
  // List<InvoiceEntity> inlist =
  // invoiceServiceI.getInvoicesByMemberId(memberId);
  // if (inlist.size() > 0) {
  // request.setAttribute("invoice", inlist.get(0));
  // request.setAttribute("memberName", inlist.get(0).getMemberName());
  // } else {
  // MemberEntity member = systemService.getEntity(MemberEntity.class,
  // memberId);
  // request.setAttribute("memberName", member.getName());
  // }
  // request.setAttribute("memberId", memberId);
  // return "carwx/bill";
  // }
  //
  // @RequestMapping(params = "txm")
  // public String txm(HttpServletRequest request, HttpServletResponse response)
  // throws Exception {
  // String memberId = request.getParameter("memberId");
  // String ticketNumber = request.getParameter("ticketNumber");
  // MemberEntity member = systemService.getEntity(MemberEntity.class,
  // memberId);
  // request.setAttribute("member", member);
  // request.setAttribute("ticketNumber", ticketNumber);
  // return "carwx/txm";
  // }
  //
  // @RequestMapping(params = "oauth")
  // public void oauth(HttpServletRequest request, HttpServletResponse response)
  // throws IOException, WxErrorException, AlipayApiException {
  // String isWx = request.getParameter("isWx");
  // if ("1".equals(isWx)) {
  // redirectWeiXin(request, response);
  // } else {
  // redirectAlipay(request, response);
  // }
  // }
  //
  // @RequestMapping(params = "saveInvoice")
  // @ResponseBody
  // public String saveInvoice(InvoiceEntity invoice, HttpServletRequest
  // request,
  // HttpServletResponse response) {
  // String orderIds = request.getParameter("orderIds");
  // String invoiceStr = request.getParameter("bills");
  // invoice = JSONObject.parseObject(invoiceStr, InvoiceEntity.class);
  // String inid = systemService.save(invoice).toString();
  // String[] orderss = orderIds.split(",");
  // for (String orderId : orderss) {
  // OrderEntity order = systemService.getEntity(OrderEntity.class, orderId);
  // order.setInvoiceId(inid);
  // order.setInvoice(CgAutoListConstant.BOOL_TRUE);
  // systemService.saveOrUpdate(order);
  // }
  // return inid;
  // }
  //
  // @RequestMapping(params = "getItemByGunId")
  // @ResponseBody
  // public String getItemByGunId(HttpServletRequest request,
  // HttpServletResponse response) {
  // String gunId = request.getParameter("gunId");
  // OilGunEntity gun = systemService.getEntity(OilGunEntity.class, gunId);
  // return gun.getGasItemName() + "," + gun.getGasItemId();
  //
  // }
  //
  // @RequestMapping(params = "getStationByLongAndLati")
  // @ResponseBody
  // public String getStationByLongAndLati(HttpServletRequest request,
  // HttpServletResponse response) {
  // String longitude = request.getParameter("longitude");
  // String latitude = request.getParameter("latitude");
  // StationUserEntity stationUser = null;
  // StationEntity station = stationService.location(Double.valueOf(longitude),
  // Double.valueOf(latitude));
  // if (station == null) {
  // stationUser = null;
  // } else
  // stationUser = systemService.findUniqueByProperty(StationUserEntity.class,
  // "departid",
  // station.getId());
  // return station == null ? ""
  // : station.getId() + "," + stationUser == null ? "" : stationUser.getId();
  // }
  //
  // @RequestMapping(params = "saveOrder")
  // @ResponseBody
  // public String saveOrder(OrderEntity order, HttpServletRequest request,
  // HttpServletResponse response) {
  // try {
  // String openid = request.getParameter("openid");
  // String alipayUserId = request.getParameter("alipayUserId");
  // String orderStr = request.getParameter("orders");
  // order = JSONObject.parseObject(orderStr, OrderEntity.class);
  // String vehicleNo = request.getParameter("vehicleNo");
  // order.setVehicleNo(vehicleNo);
  //
  // StationUserEntity user =
  // systemService.findUniqueByProperty(StationUserEntity.class, "id",
  // order.getStationUserId());
  // logger.info("=======stationuserId:" + order.getStationUserId());
  // Assert.assertArgumentNotNull(user, "user");
  // if (user != null && StringUtils.isNotBlank(user.getId())) {
  // // 取用户所属组织
  // List<StationEntity> stations =
  // stationUserService.getStations(user.getId());
  // if (stations.size() > 0) {
  // StationEntity station = stations.get(0);
  // user.setCurrentDepart(station);
  // }
  // }
  //
  // MemberEntity member = getMember(openid, alipayUserId);
  // Assert.assertArgumentNotNull(member, "member");
  // order.setMemberId(member.getId());
  // order.setMemberName(member.getName());
  // order.setMemberMobilephone(member.getMobilephone());
  // order.setCreateName(member.getName());
  // order.setCreateBy(member.getId());
  // order.setCreateDate(new Date());
  // order.setSysOrgCode(
  // user.getCurrentDepart() == null ? null :
  // user.getCurrentDepart().getOrgCode());
  // order.setState(OrderStates.NONPAY);
  // order.setCheckState(CheckStates.UNCHECKED);
  // String id = (String) orderService.save(order);
  // return id;
  // } catch (Exception e) {
  // logger.error("保存订单失败", e);
  // return "";
  // }
  // }
  //
  // private MemberEntity getMember(String openid, String alipayUserId) {
  // MemberEntity member = null;
  // if (StringUtils.isNotEmpty(openid)) {
  // member = systemService.findUniqueByProperty(MemberEntity.class, "wxid",
  // openid);
  //
  // // 出现过找不到会员的情况， 所以这里再次保存一次
  // if (member == null) {
  // WxFansEntity fans = wxFansService.getByOpenId(openid);
  // member = new MemberEntity();
  // member.setWxid(openid);
  // member.setGrade(MemberGrade.GRADE_1);
  // member.setStatus(MemberState.NORMAL);
  // if (fans != null) {
  // member.setName(fans.getNickname());
  // member.setImgurl(fans.getHeadimgurl());
  // }
  // mbrService.save(member);
  // }
  //
  // } else if (StringUtils.isNotEmpty(alipayUserId)) {
  // member = mbrService.getByAlipayid(alipayUserId);
  //
  // // 出现过找不到会员的情况， 所以这里再次保存一次
  // if (member == null) {
  // AlipayGzuserinfo user = userDao.getByUserid(alipayUserId);
  // member = new MemberEntity();
  // member.setWxid(openid);
  // member.setGrade(MemberGrade.GRADE_1);
  // member.setStatus(MemberState.NORMAL);
  // if (user != null) {
  // member.setName(user.getName());
  // member.setImgurl(user.getAvatar());
  // }
  // mbrService.save(member);
  // }
  // }
  //
  // return member;
  // }
  //
  // @RequestMapping(params = "saveMemVehicar")
  // @ResponseBody
  // public String saveMemVehicar(MemberVehicleEntity vehicle,
  // HttpServletRequest request,
  // HttpServletResponse response) throws Exception {
  // String vehicleStr = request.getParameter("vehicle");
  // vehicle = JSONObject.parseObject(vehicleStr, MemberVehicleEntity.class);
  // Serializable id = systemService.save(vehicle);
  // return id.toString();
  // }
  //
  // @RequestMapping(params = "saveComment")
  // @ResponseBody
  // public String saveComment(HttpServletRequest request, HttpServletResponse
  // response)
  // throws Exception {
  // String openid = request.getParameter("openid");
  // WxFansEntity fans = WxContext.getWxUser();
  // if (fans == null) {
  // fans = systemService.findUniqueByProperty(WxFansEntity.class, "openid",
  // openid);
  // if (fans != null) {
  // WxContext.setWxUser(fans);
  // }
  // }
  // String commentStr = request.getParameter("comment");
  // String commentDetailsStr = request.getParameter("commentDetails");
  // CommentEntity comment = JSONObject.parseObject(commentStr,
  // CommentEntity.class);
  // List<CommentDetailEntity> commentDetails =
  // JSONObject.parseArray(commentDetailsStr,
  // CommentDetailEntity.class);
  // String id = "";
  // if (StringUtils.isEmpty(comment.getId())) {
  // comment.setCommentDate(new Date());
  // id = systemService.save(comment).toString();
  // } else {
  // systemService.saveOrUpdate(comment);
  // id = comment.getId();
  // List<CommentDetailEntity> commentDetailsdel = systemService
  // .findByProperty(CommentDetailEntity.class, "commentId", id);
  // systemService.deleteAllEntitie(commentDetailsdel);
  // }
  //
  // for (CommentDetailEntity commentDetailEntity : commentDetails) {
  // commentDetailEntity.setCommentId(id);
  // systemService.saveOrUpdate(commentDetailEntity);
  // }
  // return id;
  // }
  //
  // private void setCouponStock(String memberId, HttpServletRequest request) {
  // List<CouponStockEntity> list =
  // systemService.findByProperty(CouponStockEntity.class, "memberId",
  // memberId);
  // List<CouponStockEntity> useableOilList = new
  // ArrayList<CouponStockEntity>();
  // List<CouponStockEntity> usedOilList = new ArrayList<CouponStockEntity>();
  // List<CouponStockEntity> useableOtherList = new
  // ArrayList<CouponStockEntity>();
  // List<CouponStockEntity> usedeOtherList = new
  // ArrayList<CouponStockEntity>();
  // for (CouponStockEntity couponStockEntity : list) {
  //
  // if (CouponType.OIL_COUPON.equals(couponStockEntity.getType())) {
  //
  // if (CouponStockState.DISTRIBUTED.equals(couponStockEntity.getState())
  // && couponStockEntity.getValidEndDate().getTime() > new Date().getTime()) {
  // useableOilList.add(couponStockEntity);
  // } else {
  // usedOilList.add(couponStockEntity);
  // }
  // } else {
  // if (CouponStockState.DISTRIBUTED.equals(couponStockEntity.getState())
  // && couponStockEntity.getValidEndDate().getTime() > new Date().getTime()) {
  // useableOtherList.add(couponStockEntity);
  // } else {
  // usedeOtherList.add(couponStockEntity);
  // }
  //
  // }
  // }
  // request.setAttribute("useableOilList", useableOilList);
  // request.setAttribute("usedOilList", usedOilList);
  // request.setAttribute("useableOtherList", useableOtherList);
  // request.setAttribute("usedeOtherList", usedeOtherList);
  //
  // }
  //
  // private void redirectWeiXin(HttpServletRequest request, HttpServletResponse
  // response)
  // throws IOException, WxErrorException {
  // if (logger.isInfoEnabled()) {
  // StringBuffer sb = new StringBuffer();
  // sb.append("url=" + request.getRequestURI());
  // sb.append("query string=" + request.getQueryString());
  // logger.info("weixin oauth url = {}", sb.toString());
  // }
  //
  // String oauthUrl = URLDecoder.decode(request.getParameter("oauthUrl"),
  // "utf-8");
  // String code = request.getParameter("code");
  // final String STATE = "STAT";
  //
  // if (code != null) {
  // if (logger.isInfoEnabled()) {
  // logger.info("oauth code = {}", code);
  // }
  //
  // try {
  // if (STATE.equals(request.getParameter("state"))) {
  // String openid = WxContext.initWxUserByOAuthCode(code).getOpenId();
  // request.setAttribute("openid", openid);
  // MemberEntity member =
  // systemService.findUniqueByProperty(MemberEntity.class, "wxid",
  // openid);
  // request.setAttribute("member", member);
  // response.sendRedirect(oauthUrl + "&openid=" + openid);
  // }
  // } catch (Exception e) {
  // logger.error("", e);
  // }
  // } else {
  // String url = wxMpService.oauth2buildAuthorizationUrl(
  // request.getRequestURL().toString() + "?" + request.getQueryString(),
  // WxConsts.OAUTH2_SCOPE_USER_INFO, STATE);
  // response.sendRedirect(url);
  // }
  // }
  //
  // private boolean redirectAlipay(HttpServletRequest request,
  // HttpServletResponse response)
  // throws AlipayApiException, IOException {
  // String oauthUrl = URLDecoder.decode(request.getParameter("oauthUrl"),
  // "utf-8");
  // String code = request.getParameter("auth_code");
  // if (StringUtils.isBlank(code)) {
  // String appid = request.getParameter("appid");
  // if (StringUtils.isBlank(appid) && ResourceUtil.getSessionUserId() != null)
  // {
  // AlipayAccount account =
  // AlipayContext.getAlipayAccount(ResourceUtil.getSessionUserId());
  // appid = account.getAppid();
  // }
  //
  // String testurl = request.getRequestURL().toString() + "?" +
  // request.getQueryString();
  // String authurl =
  // "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=" + appid
  // + "&scope=auth_userinfo&redirect_uri=" + URLEncoder.encode(testurl, "GBK");
  // response.sendRedirect(authurl);
  // return true;
  // } else {
  // AlipaySystemOauthTokenRequest oauthTokenRequest = new
  // AlipaySystemOauthTokenRequest();
  // oauthTokenRequest.setCode(code);
  // oauthTokenRequest.setGrantType("authorization_code");
  // AlipayClient alipayClient = AlipayClientFactory
  // .getAlipayClient(AlipayContext.getAlipayConfigByAppid(request.getParameter("appid")));
  // AlipaySystemOauthTokenResponse oauthTokenResponse =
  // alipayClient.execute(oauthTokenRequest);
  //
  // // 成功获得authToken
  // if (null == oauthTokenResponse || !oauthTokenResponse.isSuccess()) {
  // logger.info("authCode换取authToken失败");
  // return false;
  // }
  //
  // // 4. 利用authToken获取用户信息
  // AlipayUserUserinfoShareRequest shareRequest = new
  // AlipayUserUserinfoShareRequest();
  // AlipayUserUserinfoShareResponse shareResponse =
  // alipayClient.execute(shareRequest,
  // oauthTokenResponse.getAccessToken());
  // if (null == shareResponse || !shareResponse.isSuccess()) {
  // logger.info("获取用户信息失败");
  // return false;
  // }
  //
  // final String alipayUserId = shareResponse.getAlipayUserId();
  // AlipayContext.initAlipayAccountByAppId(alipayUserId,
  // request.getParameter("appid"));
  //
  // AlipayGzuserinfo userInfo = alipayGzuserinfoDao.getByUserid(alipayUserId);
  // if (userInfo == null) {
  // userInfo = new AlipayGzuserinfo();
  // userInfo.setUserid(alipayUserId);
  // userInfo.setAccountid(AlipayContext.getAlipayAccountId(alipayUserId));
  // userInfo.setCreateDate(new Date());
  // userInfo.setId(UUID.randomUUID().toString().replaceAll("-", ""));
  // userInfo.setSubscribeStatus(AlipayGzuserinfo.SUBSCRIBE_STATUS_UNFOLLOW);
  // userInfo.setName(shareResponse.getNickName());
  // userInfo.setProvince(shareResponse.getProvince());
  // if ("M".equals(shareResponse.getGender())) {
  // userInfo.setGender("1");
  // } else if ("F".equals(shareResponse.getGender())) {
  // userInfo.setGender("0");
  // }
  // if (StringUtils.isNotBlank(shareResponse.getAvatar())) {
  // userInfo.setAvatar(shareResponse.getAvatar());
  // }
  // userDao.insert(userInfo);
  // } else if (!Objects.equal(userInfo.getName(), shareResponse.getNickName()))
  // {
  // userInfo.setName(shareResponse.getNickName());
  // userInfo.setProvince(shareResponse.getProvince());
  // if ("M".equals(shareResponse.getGender())) {
  // userInfo.setGender("1");
  // } else if ("F".equals(shareResponse.getGender())) {
  // userInfo.setGender("0");
  // }
  // if (StringUtils.isNotBlank(shareResponse.getAvatar())) {
  // userInfo.setAvatar(shareResponse.getAvatar());
  // }
  // alipayGzuserinfoDao.update(userInfo);
  // }
  //
  // MemberEntity mbr = mbrService.getByAlipayid(alipayUserId);
  // if (mbr == null) {
  // mbr = new MemberEntity();
  // mbr.setName(shareResponse.getNickName());
  // mbr.setAlipayid(alipayUserId);
  // mbr.setImgurl(shareResponse.getAvatar());
  // mbr.setGrade(MemberGrade.GRADE_1);
  // mbr.setStatus(MemberState.NORMAL);
  // mbrService.save(mbr);
  // } else if (!Objects.equal(mbr.getName(), shareResponse.getNickName())) {
  // mbr.setName(shareResponse.getNickName());
  // if (StringUtils.isNotBlank(shareResponse.getAvatar())) {
  // mbr.setImgurl(shareResponse.getAvatar());
  // }
  // mbrService.saveOrUpdate(mbr);
  // }
  // request.setAttribute("member", mbr);
  //
  // request.setAttribute("alipayUserId", alipayUserId);
  // logger.info("获取用户信息成功：" + shareResponse.getBody());
  // response.sendRedirect(oauthUrl + "&alipayUserId=" + alipayUserId);
  // return false;
  // }
  // }
  //
  // @RequestMapping(params = "lottery")
  // public String lottery(HttpServletRequest request, HttpServletResponse
  // response) {
  // String billNumber = request.getParameter("billNumber");
  // request.setAttribute("billNumber", billNumber);
  // return "carwx/lottery";
  // }
  //
  // @RequestMapping(params = "distributeCoupon")
  // @ResponseBody
  // public AjaxJson distributeCoupon(HttpServletRequest request,
  // HttpServletResponse response) {
  // String billNumber = request.getParameter("billNumber");
  // String message = null;
  // AjaxJson j = new AjaxJson();
  // j.setSuccess(false);
  // message = "十分遗憾,本次未抽中任何奖品";
  // if (!TextUtils.isEmpty(billNumber)) {
  // try {
  // String result = couponStockService.drawLottery(billNumber);
  // if (!StringUtils.isEmpty(result)) {
  // message = result;
  // j.setSuccess(true);
  // }
  // } catch (Exception e) {
  // e.printStackTrace();
  // }
  // } else {
  // throw new BusinessException("加油单号不能为空");
  // }
  // j.setMsg(message);
  // return j;
  // }

}
